package edu.zhuoxun.blogserver.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import edu.zhuoxun.blogserver.entity.Book;
import edu.zhuoxun.blogserver.entity.Page;
import edu.zhuoxun.blogserver.entity.Result;
import edu.zhuoxun.blogserver.map.BookMapper;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
public class BookController {
    @Resource
    public BookMapper bookMapper;

    @GetMapping("api/book/page")
    @ResponseBody
    public Result<Page<Book>> getBooks(int category, int page, int size){
        Result<Page<Book>> result = new Result<>();
        QueryWrapper<Book> queryWrapper = new QueryWrapper<Book>().eq(category != 0, "c_id", category);
        Page<Book> bookPage = new Page<>(queryWrapper, bookMapper, page, size);
        result.setCode(200);
        result.setData(bookPage);
        result.setMessage("OK");
        return result;
    }
}
